package com.taotao.controller;

import com.taotao.TaotaoResult;
import com.taotao.pojo.TreeNode;
import com.taotao.service.ContentCatgoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by mafuhua on 2017/9/29.
 */
@Controller
@RequestMapping("/content/category")
public class ContentCategoryController {
    @Autowired
    private ContentCatgoryService contentCatgoryService;

    @RequestMapping("/list")
    @ResponseBody
    public List<TreeNode> getContentCatList(@RequestParam(value = "id", defaultValue = "0") long parentId) {
        List<TreeNode> contentCatList = contentCatgoryService.getContentCatList(parentId);
        return contentCatList;
    }

    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult createContentCat(long parentId, String name) {
        TaotaoResult taotaoResult = contentCatgoryService.insertCategory(parentId, name);
        return taotaoResult;
    }

    @RequestMapping("/update")
    @ResponseBody
    public TaotaoResult updateContentCat(long id, String name) {
        TaotaoResult taotaoResult = contentCatgoryService.updateCategory(id, name);
        return taotaoResult;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteContentCat(@RequestParam(value = "parentId", defaultValue = "-1") long parentId, long id) {
        TaotaoResult taotaoResult = contentCatgoryService.deleteCategory(parentId, id);
        return taotaoResult;
    }


}
